/*
 * Copyright 2013 Robert Peszek.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *     http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

	package fpig.lists.structures

import fpig.groovylists.functions.InAndOutOfFunLists;
import fpig.lists.functions.Infinity;

/**
* Base class allowing different implementations of functional lists
*
* Should be viewed as internal class used by list functions only or for OO type of coding.
*
* About Generics typing:
* public keywords added so the syntax <S> FunList<S> build(S val, Closure tailEval) does not show as errors.
* Generics info is provided to clarify the purpose of each method.
* It is totally OK to prepend Object to FunList of Strings, getting List of Objects from it.
* EMPTYLIST is polymorphic (the same list works for all types) but there is no way to describe that with Java Generics!
* 
* In any rate, Groovy does not care. 
*
* http://code.google.com/p/fpiglet/
* @author Robert Peszek
*/
abstract class FunList<T> {
    private static final FunList _EMPTYLIST = new LazyList() //TODO where should that be defined?
    public static FunList getEMPTYLIST(Map props = null) {
        _EMPTYLIST
    }
    public static FunList<T> fromOoList(List<T> fromL, Map props = null) {
        InAndOutOfFunLists.funlistIn(fromL, props)
    }
    public static FunList<T> funStreamFrom(n) {
        Infinity.streamFrom(n)
    }

    public abstract boolean isEmpty()
    public abstract T getHead()
    public abstract FunList<T> getTail()
	
	/**
	 * Generics info provided to convey purpose only.
	 * Closure tailEval needs to return T and <S super T>
	 * 
	 * In SCALA you would write [S >: T].
	 */
    public abstract <S> FunList<S> build(S val, Closure tailEval)
}
